package com.ebupt.migu.music.userGroup.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ebupt.migu.common.pojo.PageCreateRequestBean;
import com.ebupt.migu.common.pojo.PageCreateResponseBean;
import com.ebupt.migu.common.pojo.ValidRequestBean;
import com.ebupt.migu.common.response.Response;
import com.ebupt.migu.music.common.constants.UserGroupConstants;
import com.ebupt.migu.music.common.entity.Page;
import com.ebupt.migu.music.common.entity.ResultObject;
import com.ebupt.migu.music.common.exception.MyException;
import com.ebupt.migu.music.common.exception.StatusEnum;
import com.ebupt.migu.music.common.util.DateUtil;
import com.ebupt.migu.music.common.util.ExportFileDataFromRedis;
import com.ebupt.migu.music.label.utils.SftpUtils;
import com.ebupt.migu.music.redis.service.RedisService;
import com.ebupt.migu.music.system.entity.SysUser;
import com.ebupt.migu.music.userGroup.entity.*;
import com.ebupt.migu.music.userGroup.mapper.CrowdMapper;
import com.ebupt.migu.music.userGroup.service.LabelService;
import com.ebupt.migu.restapi.RestHttpPost;
import freemarker.template.Configuration;
import freemarker.template.TemplateException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.Cursor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created by Intellij IDEA.
 * User:  liuyangyang@cd.ebupt.com
 * Date:  2019/9/4
 */
@Slf4j
@Service
public class LabelServiceImpl implements LabelService {

    @Autowired
    private CrowdMapper crowdMapper;
    @Autowired
    Configuration configuration;
    @Resource
    RedisService redisService;
    @Resource
    ExportFileDataFromRedis exportFileDataFromRedis;
    @Resource
    SftpUtils sftpUtils;
    @Value("${label.prefix}")
    private String LABEL_PREFIX;
    @Value("${label.page_create}")
    private String PAGE_CREATE;
    @Value("${label.customer_valid}")
    private String CUSTOMER_VALID;
    @Value("${label.customer_create}")
    private String CUSTOMER_CREATE;

    /**
     * 查询省份城市列表
     *
     * @param paramMap
     * @return
     */
    @Override
    public ResultObject queryAreaList(Map<String, Object> paramMap) {
        // miguDpi：1-咪咕音乐；2-DPI；
        if (null == paramMap.get("miguDpi")) {
            throw new MyException(StatusEnum.BUSINID, "请填写来源平台信息！");
        }
        int miguDpi = Integer.parseInt(paramMap.get("miguDpi").toString());
        List<AreaInfo> provinces;
        if (miguDpi == 1) {
            provinces = crowdMapper.queryMiguProvince();
        } else {
            provinces = crowdMapper.queryDPIProvince();
        }
        JSONArray options = areaInfoToJsonArray(miguDpi, provinces);
        ResultObject<Object> res = new ResultObject<>();
        res.setData(options);
        return res;
    }

    /**
     * 查询年龄段划分列表
     *
     * @return
     */
    @Override
    public ResultObject queryAgeDivisionList() {
        List<AgeDivision> ageDivisions = crowdMapper.queryAgeDivisionList();
        ResultObject<List<AgeDivision>> res = new ResultObject<>();
        res.setData(ageDivisions);
        return res;
    }

    /**
     * 查询等级划分列表
     *
     * @return
     */
    @Override
    public ResultObject queryGradeDivisionList() {
        List<GradeDivision> gradeDivisions = crowdMapper.queryGradeDivisionList();
        ResultObject<List<GradeDivision>> res = new ResultObject<>();
        res.setData(gradeDivisions);
        return res;
    }

    /**
     * 通过标签创建人群
     * 1. 验证是否自动保存草稿箱：isDraft 0-非草稿箱；1-草稿箱；
     * 2. 解析标签JSON，选择静态标签创建或是动态标签创建
     *
     * @return
     */
    @Override
    public ResultObject createByLabel(Map<String, Object> params) throws IOException, TemplateException {
        ResultObject res = new ResultObject();
        // 验证是否需要存入草稿箱 1-非草稿箱； 0-草稿箱；
        if (null == params.get("saveType")) {
            throw new MyException(StatusEnum.BUSINID, "saveType参数不可为空！");
        }
        int saveType = Integer.parseInt(params.get("saveType").toString());
        if (saveType != 0 && saveType != 1) {
            throw new MyException(StatusEnum.BUSINID, "saveType参数值错误！");
        }
        // 验证用户群名称
        if (null == params.get("userGroupName") || StringUtils.isBlank(params.get("userGroupName").toString())) {
            throw new MyException(StatusEnum.BUSINID, "用户群名称不可为空！");
        }
        String userGroupName = params.get("userGroupName").toString();
        String gid = null;
        if (null != params.get("groupId") && !("").equals("groupId")) {
            gid = params.get("groupId").toString();
        }
        // 判断人群名称是否存被占用
        Map<String, Object> map = new HashMap<>();
        map.put("userGroupName", userGroupName);
        map.put("groupId", gid);
        if (crowdMapper.isUserGroupNameExistCnt(map) > 0) {
            throw new MyException(StatusEnum.NAME_ALREADY_EXIST, "人群名称被占用，请尝试换一个人群名称！");
        }

        // 生成用户群ID
        String groupId = String.valueOf(params.get("groupId"));
        // 保存到草稿箱
        if (saveType == 0) {
            try {
                //检查数据库是否存在同名用户群:1- 存在同名用户群则更新当前用户群； 2- 没有则创建新的用户群；
                HashMap<String, Object> isExist = crowdMapper.isUserGroupNameExist(params.get("userGroupName").toString());
                if (isExist == null) {
                    // 创建状态设置为保存入草稿箱
                    // 默认是动态标签创建
                    params.put("createWay", UserGroupConstants.CREATE_BY_DYNAMIC_LABEL);
                    params.put("createStatus", UserGroupConstants.WAITING_FOR_SUBMISSION);
                    crowdMapper.deleteCustomerTmp(params);
                    crowdMapper.createUserGroup(params);
                } else {
                    // 根据用户群ID更新人群信息
                    params.put("groupId", isExist.get("groupId").toString());
                    crowdMapper.updateCrowd(params);
                }
            } catch (Exception e) {
                log.error("保存草稿箱失败！", e);
                throw new MyException(StatusEnum.CREATE_USER_GROUP_ERROR, "自动保存草稿箱失败！");
            }
            res.setMsg("保存草稿箱成功！");
            return res;
        }
        params.put("createWay", UserGroupConstants.CREATE_BY_DYNAMIC_LABEL);
        params.put("createStatus", UserGroupConstants.BEING_CREATED);
        // 客群有效信息上报
        ValidRequestBean validRequestBean = new ValidRequestBean();
        validRequestBean.setCustomerId(groupId);
        validRequestBean.setStatus(1);
        validRequestBean.setIsDynamic(Integer.valueOf(String.valueOf(params.get("isDynamicCustomer"))));
        log.info("客群有效信息上报：{}", validRequestBean.toString());
        RestHttpPost post = new RestHttpPost();
        Response<String> response = post.doRest(validRequestBean, LABEL_PREFIX + CUSTOMER_VALID);
        if (!"0000".equals(response.getHead().getResponseCode())) {
            res.setCode(StatusEnum.ERROR.getCode());
            res.setMsg("统一标签服务平台创建客群失败");
            return res;
        } else {
            JSONObject json = JSON.parseObject(response.getResponse());
            if (!"0000".equals(json.get("code"))) {
                res.setCode(StatusEnum.ERROR.getCode());
                res.setMsg("统一标签服务平台创建客群失败");
                return res;
            }
        }
        crowdMapper.deleteCustomerTmp(params);
        crowdMapper.createUserGroup(params);
        // 在hive_delay_update表创建记录
        hiveDelayUpdate(groupId, params.get("groupAttribute").toString());
        res.setMsg("创建成功！");
        return res;
    }

    /**
     * 通过人群名称查询人群ID
     *
     * @param params
     * @return
     */
    @Override
    public ResultObject queryByName(Map<String, Object> params) {
        ResultObject res = new ResultObject();
        // 验证是否需要存入草稿箱 1-非草稿箱； 0-草稿箱；
        if (null == params.get("userGroupName")) {
            throw new MyException(StatusEnum.BUSINID, "saveType参数不可为空！");
        }
        String userGroupName = params.get("userGroupName").toString();
        // 通过人群名称查询人群ID
        String groupId = crowdMapper.queryByName(userGroupName);
        Map<String, String> map = new HashMap<>();
        map.put("groupId", groupId);
        res.setMsg("查询成功");
        res.setData(map);
        return res;
    }

    /**
     * 省份城市列表转换成前端可展示的Json格式
     *
     * @param provinces
     * @return
     */
    private JSONArray areaInfoToJsonArray(int miguDpi, List<AreaInfo> provinces) {
        JSONArray options = new JSONArray();
        for (AreaInfo province : provinces) {
            JSONObject pro = new JSONObject();
            pro.put("value", province.getProvinceName());
            pro.put("label", province.getProvinceName());
            pro.put("regionCode", province.getAppProvinceCode());
            List<AreaInfo> areas = new ArrayList<>();
            Map<String, Object> params = new HashMap<>();
            params.put("provinceCode", province.getProvinceCode());
            if (miguDpi == 1) {
                params.put("code", 1);
                areas = crowdMapper.queryArea(params);
            } else {
                params.put("code", 2);

                areas = crowdMapper.queryArea(params);
            }
            JSONArray children = new JSONArray();
            for (AreaInfo area : areas) {
                JSONObject city = new JSONObject();
                city.put("value", area.getAreaName());
                city.put("label", area.getAreaName());
                city.put("regionCode", area.getAppAreaCode());
                children.add(city);
            }
            pro.put("children", children);
            options.add(pro);
        }
        return options;
    }


    @Override
    public void refresh() {
        List<HashMap<String, Object>> maps = new ArrayList<>();
        maps = crowdMapper.refresh();
        for (HashMap<String, Object> map : maps) {
            String gid = map.get("groupId").toString();
            String json = map.get("groupAttribute").toString();
            hiveDelayUpdate(gid, json);
        }
    }

    /**
     * 获取白金会员类型
     *
     * @return
     */
    @Override
    public ResultObject vipCode() {
        List<HashMap<String, String>> codes = crowdMapper.vipCode();
        JSONArray datas = new JSONArray();
        // 普通会员
        JSONArray common = new JSONArray();
        //联合会员
        JSONArray union = new JSONArray();
        for (HashMap<String, String> code : codes) {
            JSONObject data = new JSONObject();
            String type = String.valueOf(code.get("vipType"));
            data.put("key", code.get("vipKey"));
            data.put("value", code.get("vipValue"));
            switch (type) {
                case "0":
                    common.add(data);
                    break;
                case "1":
                    union.add(data);
                    break;
            }
        }
        datas.add(common);
        datas.add(union);
        log.info(datas.toJSONString());
        ResultObject res = new ResultObject();
        res.setCode(StatusEnum.SUCCESS.getCode());
        res.setMsg(StatusEnum.SUCCESS.getMsg());
        res.setData(datas);
        return res;
    }

    /**
     * 创建临时客群
     *
     * @param params
     * @return
     */
    @Override
    public ResultObject createTmp(Map<String, Object> params) {
        ResultObject res = new ResultObject();
        try {
            // 生成用户群ID
            Date date = new Date();
            String groupId = "BQ" + DateUtil.parseDateToStr(date, DateUtil.DATE_TIME_FORMAT_YYYYMMDDHHMISS);
            params.put("groupId", groupId);
            params.put("createWay", UserGroupConstants.CREATE_BY_DYNAMIC_LABEL);
            params.put("createStatus", UserGroupConstants.TMP);
            crowdMapper.createUserGroup(params);
            Map<String, String> info = new HashMap<>();
            info.put("groupId", groupId);
            res.setCode(StatusEnum.SUCCESS.getCode());
            res.setMsg(StatusEnum.SUCCESS.getMsg());
            // 调用统一标签服务平台接口获取session
            PageCreateRequestBean pageCreateRequestBean = new PageCreateRequestBean();
            pageCreateRequestBean.setTimestamp(DateUtil.getTimestamp());
            pageCreateRequestBean.setUserId(String.valueOf(params.get("creatorId")));
            pageCreateRequestBean.setCreatorName(String.valueOf(params.get("creatorName")));
            // 统一标签服务为1设置了最高优先级
            pageCreateRequestBean.setGroupId("1");
            log.info("请求参数：{}", pageCreateRequestBean.toString());
            RestHttpPost post = new RestHttpPost();
            Response<String> response = post.doRest(pageCreateRequestBean, LABEL_PREFIX + PAGE_CREATE);
            if ("0000".equals(response.getHead().getResponseCode())) {
                PageCreateResponseBean pageCreateResponseBean = JSON.parseObject(response.getResponse(), PageCreateResponseBean.class);
                info.put("sessionId", pageCreateResponseBean.getSessionId());
            }
            res.setData(info);
            return res;
        } catch (Exception e) {
            log.error("创建临时客群失败：{}", e.getMessage());
            res.setCode(StatusEnum.ERROR.getCode());
            res.setMsg(StatusEnum.ERROR.getMsg());
            return res;
        }
    }

    /**
     * 查询静态标签明细
     *
     * @param params
     * @return
     */
    @Override
    public ResultObject queryStaticCustomerInfo(Map<String, Object> params) {
        ResultObject res = new ResultObject();
        res.setCode(StatusEnum.SUCCESS.getCode());
        res.setMsg(StatusEnum.SUCCESS.getMsg());
        res.setData(crowdMapper.queryStaticCustomerInfo(params));
        return res;
    }

    @Override
    public ResultObject<Map<String, String>> getSessionId(SysUser user) {
        ResultObject<Map<String, String>> res = new ResultObject<>();
        try {
            res.setCode(StatusEnum.SUCCESS.getCode());
            res.setMsg("获取成功");
            // 调用统一标签服务平台接口获取sessionId
            PageCreateRequestBean pageCreateRequestBean = new PageCreateRequestBean(user.getLoginName(),
                    user.getUserName(), DateUtil.getTimestamp(), "1");
            log.info("请求参数：{}", pageCreateRequestBean);
            Response<String> response = new RestHttpPost().doRest(pageCreateRequestBean, LABEL_PREFIX + PAGE_CREATE);
            if ("0000".equals(response.getHead().getResponseCode())) {
                String sessionId = JSON.parseObject(response.getResponse(), PageCreateResponseBean.class).getSessionId();
                Map<String, String> data = new HashMap<>();
                data.put("sessionId", sessionId);
                res.setData(data);
            }
        } catch (Exception e) {
            log.error("获取sessionId失败，{}", e.getMessage());
            res.setCode(StatusEnum.ERROR.getCode());
            res.setMsg("无法获取sessionId");
            res.setData(null);
        }
        return res;
    }

    @Override
    @Transactional(rollbackFor = MyException.class)
    public ResultObject<String> batchSaveCustomerInfo(SplitGroupDTO splitGroupDTO, SysUser user) {
        log.info("分箱信息：{}", splitGroupDTO);
        String customerId = splitGroupDTO.getCustomerId();
        List<UserGroupInfo> userGroupInfoList = splitGroupDTO.getGroupInfoList();
        if (customerId == null) {
            throw new MyException(StatusEnum.BUSINID, "原始分箱客群id为空");
        }
        // 获取客群信息并同步到文件夹
        HashMap<String, Object> map = crowdMapper.queryByGroupID(customerId);
        String createWay = map.get("createWay").toString();
        // 分箱客群不支持再分箱
        if ("11".equals(createWay)) {
            throw new MyException(StatusEnum.BUSINID, "当前客群不支持再分箱操作");
        }
        String createStatus = map.get("createStatus").toString();
        if (!"5".equals(createStatus)) {
            throw new MyException(StatusEnum.ERROR, "当前客群未创建完成，不支持分箱");
        }
        String isStaticCustomer = map.get("isStaticCustomer").toString();
        // 查询数据库所有分箱用户群ID和名称
        List<UserGroupInfo> userGroupInfos = crowdMapper.queryByStatus();
        List<String> groupIds = new ArrayList<>();
        List<String> userGroupNames = new ArrayList<>();
        userGroupInfos.forEach(u -> {
            groupIds.add(u.getGroupId());
            userGroupNames.add(u.getUserGroupName());
        });
        // 判断分箱客群属于标签侧还是音乐侧
        if ("1".equals(isStaticCustomer)) {
            userGroupInfoList.forEach(u -> {
                giveValueToUserGroup(user, groupIds, userGroupNames, u, map);
                u.setCreateStatus((byte) 4);
            });
        } else {
            // 循环遍历用户信息并赋值
            userGroupInfoList.forEach(u -> {
                giveValueToUserGroup(user, groupIds, userGroupNames, u, map);
                u.setCreateStatus((byte) 1);
            });
            // 音乐侧需同步客群手机号至ftp目录
            String time = DateUtil.getTimestamp();
            String phoneFileName = customerId + "_msisdn" + "_" + time + ".txt";
            String uidFileName = customerId + "_uid" + "_" + time + ".txt";
            String deviceFileName = customerId + "_device" + "_" + time + ".txt";
            Cursor<String> uidCursor = redisService.scan(customerId + "-uid");
            exportFileDataFromRedis.export(uidCursor, uidFileName);
            Cursor<String> deviceCursor = redisService.scan(customerId + "-imei");
            exportFileDataFromRedis.export(deviceCursor, deviceFileName);
            Cursor<String> phoneCursor = redisService.scan(customerId + "-phone");
            exportFileDataFromRedis.syncExport(phoneCursor, phoneFileName);
            // 将文件上传到label_sftp中
            boolean b = sftpUtils.syncToLabel(phoneFileName);
            if (!b) {
                throw new MyException(StatusEnum.ERROR, "上传文件失败");
            }
            // 通知标签平台获取分箱文件
            CustomerSplitRequestBean customerSplitRequestBean = new CustomerSplitRequestBean();
            customerSplitRequestBean.setCustomerId(customerId);
            customerSplitRequestBean.setCustomerName(map.get("userGroupName").toString());
            customerSplitRequestBean.setUserId(user.getUserName());
            customerSplitRequestBean.setGroupId("1");
            customerSplitRequestBean.setPhonePath(phoneFileName);
            String responseCode = doPost(customerSplitRequestBean);
            log.info("通知标签平台分箱，返回响应码：{}", responseCode);
        }
        try {
            // 设置用户信息完毕，批量添加用户信息
            crowdMapper.batchSaveCustomerInfo(userGroupInfoList);
        } catch (Exception e) {
            log.info("创建人群失败：{}", e.getMessage());
            throw new MyException(StatusEnum.CREATE_USER_GROUP_ERROR, "创建用户群信息失败");
        }
        return new ResultObject<>(StatusEnum.SUCCESS.getCode(),
                StatusEnum.SUCCESS.getMsg(), "分箱完成，批量添加成功");
    }

    /**
     * 视频彩铃标签-级联菜单查询
     *
     * @param params
     * @return
     */
    @Override
    public ResultObject dropDownMenus(Map<String, Object> params) {
        ResultObject res = new ResultObject();
        res.setCode(StatusEnum.SUCCESS.getCode());
        res.setMsg(StatusEnum.SUCCESS.getMsg());
        Page<HashMap<String, Object>> page = new Page<>();
        int total = 0;
        List<HashMap<String, Object>> data = new ArrayList<>();
        if ("1".equals(params.get("level"))) {
            total = 0;
            data = crowdMapper.queryLevel1(params);
        }
        if ("2".equals(params.get("level"))) {
            total = crowdMapper.queryTotalLevel2(params);
            data = crowdMapper.queryLevel2(params);
        }
        if ("3".equals(params.get("level"))) {
            total = crowdMapper.queryTotalLevel3(params);
            data = crowdMapper.queryLevel3(params);
        }
        page.setTotal(total);
        page.setData(data);
        res.setData(page);
        return res;
    }

    /**
     * 给分箱客群赋值
     *
     * @param user           用户信息
     * @param groupIds       数据库所有客群id
     * @param userGroupNames 数据库所有客群名称
     * @param u              当前客群
     * @param map            源客群信息
     */
    private void giveValueToUserGroup(SysUser user, List<String> groupIds, List<String> userGroupNames, UserGroupInfo u, HashMap<String, Object> map) {
        if (null == u.getGroupId() || u.getUserGroupName() == null) {
            throw new MyException(StatusEnum.BUSINID, StatusEnum.BUSINID.getMsg());
        }
        if (groupIds.contains(u.getGroupId()) || userGroupNames.contains(u.getUserGroupName())) {
            throw new MyException(StatusEnum.NAME_ALREADY_EXIST, "人群被占用，请尝试换一个人群id或名称！");
        }
        u.setCreatorId(user.getLoginName());
        u.setCreatorName(user.getUserName());
        u.setCreatorDepartment(user.getDeptName());
        u.setCreatorPhone(user.getMobile());
        u.setCreatorEmail(user.getEmail());
        u.setCreateWay((byte) 11);
        u.setIsDynamicCustomer(Byte.valueOf(map.get("isDynamicCustomer").toString()));
        u.setIsStaticCustomer(Byte.valueOf(map.get("isStaticCustomer").toString()));
    }

    /**
     * 将分箱信息发送TSG端
     *
     * @param bean 分箱客群信息
     * @return 响应码
     */
    private String doPost(CustomerSplitRequestBean bean) {
        log.info("分箱通知信息：{}", bean);
        RestHttpPost post = new RestHttpPost();
        Response<String> response = post.doRest(bean, LABEL_PREFIX + CUSTOMER_CREATE);
        return response.getHead().getResponseCode();
    }

    /**
     * hive是否需要延迟更新
     *
     * @param gid
     * @param json
     */
    private void hiveDelayUpdate(String gid, String json) {
        //JSON转换成对应的JavaBean
        AttributeBean bean = JSON.parseObject(json, AttributeBean.class);
        Map<String, Object> map = new HashMap<>();
        map.put("groupId", gid);
        //时间类型  1：过去时段 2 ：未来时段 3：过去某天 4：未来某天 5：自定义区间 6：过去时段（周）7:过去某周
        if (StringUtils.isNotBlank(bean.getDateType())) {
            String dateType = bean.getDateType();
            String dayCont = bean.getDayCont();
            //  和过去一天有关，延迟更新：1- 不延迟； 2- 延迟；
            //  dayType：1
            //  dayType：3    dayCont:1
            //  dayType :5   dateEnd:今天的前一天
            if (dateType.equals("1") || (dateType.equals("3") && dayCont.equals("1"))) {
                map.put("delayUpdate", 2);
            } else if (dateType.equals("5")) {
                // dateEnd: 20191209
                String dateEnd = bean.getDateEnd();
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DateUtil.DATE_FORMAT_YYYYMMDD);
                Calendar calendar = new GregorianCalendar();
                calendar.setTime(new Date());
                calendar.add(Calendar.DATE, -1);
                String yesterday = simpleDateFormat.format(calendar.getTime());
                if (dateEnd.equals(yesterday)) {
                    map.put("delayUpdate", 2);
                }
            } else {
                map.put("delayUpdate", 1);
            }
        } else {
            map.put("delayUpdate", 1);
        }
        if (null != map.get("delayUpdate")) {
            crowdMapper.createHiveDelayUpdateInfo(map);
        }
    }

    /**
     * 验证人群是否由动态标签创建
     *
     * @param json
     * @return
     */
    public boolean isDyna(String json) {
        if (StringUtils.isBlank(json)) {
            throw new MyException(StatusEnum.BUSINID, "标签属性不可为空！");
        }

        //JSON转换成对应的JavaBean
        AttributeBean bean = JSON.parseObject(json, AttributeBean.class);

        //时间类型  1：过去时段 2 ：未来时段 3：过去某天 4：未来某天 5：自定义区间 6：过去时段（周）7:过去某周
        if (StringUtils.isNotBlank(bean.getDateType())) {
            return true;
        }
        // 来源平台页面选择
        // 1：咪咕音乐 2：DPI
        if (StringUtils.isNotBlank(bean.getUserRadio()) && "2".equals(bean.getUserRadio())) {
            return true;
        }
        //时间选择-开始时间
        if (StringUtils.isNotBlank(bean.getDateStart())) {
            return true;
        }
        //时间选择-结束时间
        if (StringUtils.isNotBlank(bean.getDateEnd())) {
            return true;
        }
        //具体天数 (日 或者 周)
        if (StringUtils.isNotBlank(bean.getDateType()) && StringUtils.isNotBlank(bean.getDayCont())) {
            return true;
        }
        //日期区间类型 1：过去 2：未来
        if (StringUtils.isNotBlank(bean.getSectionType())) {
            return true;
        }
        //未来时间区间
        if (!"[]".equals(bean.getDate1())) {
            return true;
        }
        //过去时间区间
        if (!"[]".equals(bean.getDate2())) {
            return true;
        }
        //周
        if (StringUtils.isNotBlank(bean.getWeek())) {
            return true;
        }
        //周选择日期
        if (StringUtils.isNotBlank(bean.getWeekPc())) {
            return true;
        }
        //是否是音频彩铃用户 1 音频彩铃用户 0 不是
        if (StringUtils.isNotBlank(bean.getCringType())) {
            return true;
        }
        //是否是音频彩铃用户 1 音频彩铃用户 0 不是
        if (StringUtils.isNotBlank(bean.getCringTypePc())) {
            return true;
        }
        //是否是视频彩铃用户 1 音频彩铃用户 0 不是
        if (StringUtils.isNotBlank(bean.getVedioCringType())) {
            return true;
        }
        //是否是视频彩铃用户 1 音频彩铃用户 0 不是
        if (StringUtils.isNotBlank(bean.getVedioCringTypePc())) {
            return true;
        }
        //是否是彩铃用户
        if (StringUtils.isNotBlank(bean.getIsMusicUser())) {
            return true;
        }
        //是否白金会员 1 白金会员 0 不是
        if (StringUtils.isNotBlank(bean.getPtFlag())) {
            return true;
        }
        //是否付费 1 付费  2 未付费
        if (StringUtils.isNotBlank(bean.getPtFeeFlag())) {
            return true;
        }
        //会员类型2 0.非会员 1.特级会员 2.高级会员 3.普通会员
        if (!"[]".equals(bean.getMemLevel())) {
            return true;
        }
        //白金会员类型 标识 1.大战包会员 2.标准版会员 3有效期白金会员 0.都不是
        if (!"[]".equals(bean.getPtType())) {
            return true;
        }
        //是否有效期白金会员 1 为是 0 为不是
        if (StringUtils.isNotBlank(bean.getPdValidFlag())) {
            return true;
        }
        //白金会员类型  中文
        if (StringUtils.isNotBlank(bean.getType())) {
            return true;
        }
        //行为状态  1 首次打开 2：持续沉默 3：开通白金会员 4：白金会员到期
        if (StringUtils.isNotBlank(bean.getNewUserFlag())) {
            return true;
        }
        //资源类型
        if (StringUtils.isNotBlank(bean.getResourceType())) {
            return true;
        }

        // 1:一元小包，2:3元小包，3:1元和3元小包
        if (StringUtils.isNotBlank(bean.getMonYuanFlag())) {
            return true;
        }

        List<ActiveArrayBean> actives = bean.getActiveArray();
        if (actives != null && actives.size() > 0) {
            return true;
        }

        /**
         * 视频彩铃id
         */
        if (StringUtils.isNotBlank(bean.getVedioCringId())) {
            return true;
        }

        /**
         * 视频彩铃风格
         */
        if (StringUtils.isNotBlank(bean.getVedioCringStyle())) {
            return true;
        }

        /**
         * 是否话费支付用户
         */
        if (StringUtils.isNotBlank(bean.getNormalHdFlag())) {
            return true;
        }

        /**
         * 是否第三方支付用户
         */
        if (StringUtils.isNotBlank(bean.getThridHdFlag())) {
            return true;
        }

        /**
         * 是否volte手机
         */
        if (StringUtils.isNotBlank(bean.getVolteFlag())) {
            return true;
        }

        /**
         * arpu值（月话费总额）
         */
        if (StringUtils.isNotBlank(bean.getArpuValue())) {
            return true;
        }

        /**
         * 时段偏好
         */
        if (StringUtils.isNotBlank(bean.getTimeFrame())) {
            return true;
        }

        return false;
    }

}
